//
//  DianPuXinXiViewController.m
//  跨界收
//
//  Created by Allen on 2018/11/4.
//  Copyright © 2018年 gztx. All rights reserved.
//

#import "DianPuXinXiViewController.h"
#import "LYLPhotoTailoringTool.h"
#import "YKPickerManager.h"
#import "AddAddressViewController.h"
#import "DianpuJianjieViewController.h"

@interface DianPuXinXiViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableview;

@end

@implementation DianPuXinXiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"店铺信息";
    
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
    UIButton *saveBtn = [[UIButton alloc]initWithFrame:CGRectMake(30, 5, SCREEN_WIDTH-60, 45)];
    saveBtn.layer.masksToBounds = YES;
    saveBtn.layer.cornerRadius = 3.0;
    saveBtn.backgroundColor = [UIColor cz_colorWithHex:0x219fdb];
    WeakSelf;
    [saveBtn addClickTargetBlock:^(UIButton *sender) {
        [weakSelf.navigationController popViewControllerAnimated:YES];
    }];
    [footerView addSubview:saveBtn];
    self.tableview.tableFooterView = footerView;
    // Do any additional setup after loading the view from its nib.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 7;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 6) {
        return 100;
    }else
        return 60;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
    }
    
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    [self initPictureDataForCell:cell indexPath:indexPath];
    return cell;
}

- (void)initPictureDataForCell:(UITableViewCell *)cell indexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
        {
            cell.textLabel.text = @"店铺LOGO/品牌";
            UIImageView *picIV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
            picIV.layer.masksToBounds = YES;
            picIV.layer.cornerRadius = 25.0;
            picIV.backgroundColor = [UIColor redColor];
            cell.accessoryView = picIV;
        }
            break;
        case 1:
        {
            cell.textLabel.text = @"店铺名称";
            cell.accessoryType = UITableViewCellAccessoryNone;
        }
            break;
        case 2:
        {
            cell.accessoryType = UITableViewCellAccessoryNone;
            cell.textLabel.text = @"联系电话";
        }
            break;
        case 3:
        {
            cell.textLabel.text = @"行业分类";
        }
            break;
        case 4:
        {
            cell.textLabel.text = @"店铺地址";
        }
            break;
        case 5:
        {
            cell.textLabel.text = @"地图定位";
        }
            break;
        case 6:
        {
            cell.accessoryType = UITableViewCellAccessoryNone;
            cell.textLabel.text = @"店铺简介";
            cell.detailTextLabel.numberOfLines = 0;
        }
            break;
            
        default:
            break;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
    
    switch (indexPath.row) {
        case 0:
        {
            [[LYLPhotoTailoringTool sharedTool]photoTailoring:^(UIImage *image) {
                UIImageView *picIV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
                picIV.layer.masksToBounds = YES;
                picIV.layer.cornerRadius = 25.0;
                picIV.image = image;
                cell.accessoryView = picIV;
            }];
        }
            break;
//        case 1:
//        {
//
//        }
//            break;
//        case 2:
//        {
//
//        }
//            break;
        case 3:
        {
            NSArray *array = @[@"服务行业",@"互联网",@"饮食行业",@"塑料行业",@"建筑行业",@"钢铁行业",@"茶叶行业",@"鸡蛋行业",@"数据行业",@"按摩行业",@"其他行业"];
            [[YKPickerManager shareManager] showGeneralPickerView:[UIColor redColor] dataArray:array defaultString:@"饮食行业" commitBlock:^(NSString *selectedItem, NSInteger index) {
                cell.detailTextLabel.text = selectedItem;
            } cancelBlock:^{
                
            }];
        }
            break;
        case 4:
        {
            AddAddressViewController *addVC = [[AddAddressViewController alloc] initWithNibName:@"AddAddressViewController" bundle:nil];
            addVC.addressBlock = ^(NSString * _Nonnull address) {
                if (address.length > 0) {
                   cell.detailTextLabel.text = address;
                }
            };
            [self.navigationController pushViewController:addVC animated:YES];
        }
            break;
        case 5:
        {
            
        }
            break;
        case 6:
        {
            DianpuJianjieViewController *jiejianVC = [[DianpuJianjieViewController alloc] initWithNibName:@"DianpuJianjieViewController" bundle:nil];
            jiejianVC.jianjieBlock = ^(NSString * _Nonnull jianjie) {
                cell.detailTextLabel.text = jianjie;
            };
            [self.navigationController pushViewController:jiejianVC animated:YES];
        }
            break;
            
        default:
            break;
    }
}
@end
